using System;
using TMPro;
using UnityEngine.UI;

namespace Game.UI {
	public class NoticeWindow : UIWindow {
		public Button ConfirmButton;
		public Button DeclineButton;

		public TMP_Text Title;
		public TMP_Text Description;

		Action _confirmAction;
		Action _declineAction;

		public void Setup(string title, string description, bool showHideButton, Action confirmAction, Action declineAction = null) {
			Title.text = title;
			Description.text = description;
			if ( CloseButton ) {
				CloseButton.gameObject.SetActive(showHideButton);
			}
			_confirmAction = confirmAction;
			_declineAction = declineAction;
			DeclineButton.gameObject.SetActive(declineAction != null);

			ConfirmButton.onClick.RemoveAllListeners();
			DeclineButton.onClick.RemoveAllListeners();
			ConfirmButton.onClick.AddListener(OnComfirmButtonClick);
			DeclineButton.onClick.AddListener(OnDeclineButtonClick);
		}

		void OnComfirmButtonClick() {
			_confirmAction?.Invoke();
			HideWindow();
		}

		void OnDeclineButtonClick() {
			_declineAction?.Invoke();
			HideWindow();
		}
	}
}
